using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class LOGINFOInfo
    {
		#region Local Variable
		public enum Field
		{
			MACHINE_NAME,
			USER_NAME,
			LOGIN_DATE,
			EXE_COMMAND
		}
		private String _MACHINE_NAME;
		private String _USER_NAME;
		private DateTime _LOGIN_DATE;
		private String _EXE_COMMAND;
		
		public String MACHINE_NAME{	get{ return _MACHINE_NAME;} set{_MACHINE_NAME = value;} }
		public String USER_NAME{	get{ return _USER_NAME;} set{_USER_NAME = value;} }
		public DateTime LOGIN_DATE{	get{ return _LOGIN_DATE;} set{_LOGIN_DATE = value;} }
		public String EXE_COMMAND{	get{ return _EXE_COMMAND;} set{_EXE_COMMAND = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public LOGINFOInfo()
		{
			_MACHINE_NAME = "";
			_USER_NAME = "";
			_LOGIN_DATE = DateTime.Now;
			_EXE_COMMAND = "";
		}
		public LOGINFOInfo(
		String MACHINE_NAME,
		String USER_NAME,
		DateTime LOGIN_DATE,
		String EXE_COMMAND
		)
		{
			_MACHINE_NAME = MACHINE_NAME;
			_USER_NAME = USER_NAME;
			_LOGIN_DATE = LOGIN_DATE;
			_EXE_COMMAND = EXE_COMMAND;
		}
		public LOGINFOInfo(DataRow dr)
		{
			if (dr != null)
			{
				_MACHINE_NAME = dr[Field.MACHINE_NAME.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.MACHINE_NAME.ToString()]);
				_USER_NAME = dr[Field.USER_NAME.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.USER_NAME.ToString()]);
				_LOGIN_DATE = dr[Field.LOGIN_DATE.ToString()] == DBNull.Value?DateTime.Now:Convert.ToDateTime(dr[Field.LOGIN_DATE.ToString()]);
				_EXE_COMMAND = dr[Field.EXE_COMMAND.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.EXE_COMMAND.ToString()]);
			}
		}
		public LOGINFOInfo(DataRowView dr)
		{
			if (dr != null)
			{
				_MACHINE_NAME = dr[Field.MACHINE_NAME.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.MACHINE_NAME.ToString()]);
				_USER_NAME = dr[Field.USER_NAME.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.USER_NAME.ToString()]);
				_LOGIN_DATE = dr[Field.LOGIN_DATE.ToString()] == DBNull.Value?DateTime.Now:Convert.ToDateTime(dr[Field.LOGIN_DATE.ToString()]);
				_EXE_COMMAND = dr[Field.EXE_COMMAND.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.EXE_COMMAND.ToString()]);
			}
		}
		public LOGINFOInfo(LOGINFOInfo objEntr)
		{			
			_MACHINE_NAME = objEntr.MACHINE_NAME;			
			_USER_NAME = objEntr.USER_NAME;			
			_LOGIN_DATE = objEntr.LOGIN_DATE;			
			_EXE_COMMAND = objEntr.EXE_COMMAND;			
		}
        #endregion Constructor
        
        #region InitTable
		public static DataTable ToDataTable()
		{
			DataTable dt = new DataTable("LOGINFO");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.MACHINE_NAME.ToString(), typeof(String)),
				new DataColumn(Field.USER_NAME.ToString(), typeof(String)),
				new DataColumn(Field.LOGIN_DATE.ToString(), typeof(DateTime)),
				new DataColumn(Field.EXE_COMMAND.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.MACHINE_NAME.ToString()] = _MACHINE_NAME;
			row[Field.USER_NAME.ToString()] = _USER_NAME;
			row[Field.LOGIN_DATE.ToString()] = _LOGIN_DATE;
			row[Field.EXE_COMMAND.ToString()] = _EXE_COMMAND;
			return row;
		}
        #endregion InitTable
    }
}
